package com.sunlands.zlcx.usercenter.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;

@Data
@Entity(name = "tz_learn_timing")
@NoArgsConstructor
@AllArgsConstructor
@Builder
@DynamicUpdate
@DynamicInsert
public class UsersLearnTimingDO implements Serializable {

    private static final long serialVersionUID = 5948869846213866329L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 学习名称
     */
    private String learnName;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 目标id
     */
    private Long targetId;

    /**
     * @see StatusEnum
     * 状态,1学习计时结束,0学习中，-1不计入学习时长和次数
     */
    private Integer status;


    /**
     * 开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date startTime;

    /**
     * 结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date endTime;

    /**
     * 学习分钟数
     */
    private Integer studyMinutes;

    /**
     * 星期几
     */
    private String week;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;

    /**
     * 类型
     */
    private Integer type;

    /**
     * 统计时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date countTime;

    private Integer startSort;

    private Integer endSort;

    private Long contentId;

    public enum StatusEnum {
        end(1, "学习计时结束"),
        start(0, "学习计时中"),
        valid(-1, "无效，不计入学习时长和学习次数");

        public final Integer code;
        public final String desc;

        StatusEnum(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }
    }

    @SuppressWarnings("all")
    public enum TypeEnums {
        ORDERNARY_COUNT_TIME(1, "ordernary_count_time", "学习计时"),
//        FREE_COUNT_TIME(2, "free_count_time", "自由学习计时"),
//        TOMATO_COUNT_TIME(3, "tomato_count_time", "番茄计时"),
//        VIDEO_COUNT_TIME(4, "video_count_time", "视频打卡"),
        LIAN_MAI(5, "lian_mai", "连麦学习"),
        TIME_LEARN_ROOM(60, "lian_mai", "连麦学习"),
                ;

        public final Integer code;
        public final String desc;
        public final String title;
        TypeEnums(Integer code, String desc, String title) {
            this.code = code;
            this.desc = desc;
            this.title = title;
        }

        public static UsersLearnTimingDO.TypeEnums create(Integer code) {
            if (null == code) {
                return null;
            }
            for (UsersLearnTimingDO.TypeEnums field : UsersLearnTimingDO.TypeEnums.values()) {
                if (code.intValue() == field.getCode()) {
                    return field;
                }
            }
            return null;
        }

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

        public String getTitle() {
            return title;
        }
    }

}
